#pragma once
#include ".\light.h"

CLight::CLight(void)
{
	ZeroMemory( &m_DirectionLight	, sizeof( D3DLIGHT9 ) );
	ZeroMemory( &m_PointLight		, sizeof( D3DLIGHT9 ) );
	ZeroMemory( &m_SpotLight		, sizeof( D3DLIGHT9 ) );
}

CLight::~CLight(void)
{
	ZeroMemory( &m_DirectionLight  , sizeof( D3DLIGHT9 ) );
	ZeroMemory( &m_PointLight		, sizeof( D3DLIGHT9 ) );
	ZeroMemory( &m_SpotLight		, sizeof( D3DLIGHT9 ) );
}

bool CLight::Init()
{
	// Setting Direction Light!!
	m_DirectionLight.Type			= D3DLIGHT_DIRECTIONAL;
	m_DirectionLight.Diffuse.r		= 1.0f;//m_pDirectionLight.Ambient.r  = m_pDirectionLight.Specular.r  = 1.0f;
	m_DirectionLight.Diffuse.g		= 1.0f;//m_pDirectionLight.Ambient.g  = m_pDirectionLight.Specular.g  = 1.0f;
	m_DirectionLight.Diffuse.b		= 1.0f;//m_pDirectionLight.Ambient.b  = m_pDirectionLight.Specular.b  = 1.0f;
	m_DirectionLight.Diffuse.a		= 1.0f;//m_pDirectionLight.Ambient.a  = m_pDirectionLight.Specular.a  = 1.0f;
	m_DirectionLight.Range			= 1000.0f;
	m_DirectionLight.Direction		= D3DXVECTOR3( 100.0f , -100.0f , 100.0f );

	g_pd3dDevice->SetLight( 0 , &m_DirectionLight );
	g_pd3dDevice->LightEnable( 0 , FALSE );


	// Setting Point Light!!
	m_PointLight.Type				= D3DLIGHT_POINT;
	m_PointLight.Diffuse.r			= m_PointLight.Ambient.r = m_PointLight.Specular.r = 0.5f;
	m_PointLight.Diffuse.g			= m_PointLight.Ambient.g = m_PointLight.Specular.g = 0.0f;
	m_PointLight.Diffuse.b			= m_PointLight.Ambient.b = m_PointLight.Specular.b = 0.0f;
	m_PointLight.Diffuse.a			= m_PointLight.Ambient.a = m_PointLight.Specular.a = 1.0f;
	m_PointLight.Range				= 100.0f;
	m_PointLight.Position			= D3DXVECTOR3( -100.0f , 50.0f , 100.0f );
	m_PointLight.Attenuation0		= 0.0f;
	m_PointLight.Attenuation1		= 0.01f;
	m_PointLight.Attenuation2		= 0.0f;
	

	g_pd3dDevice->SetLight( 1 , &m_PointLight );
	g_pd3dDevice->LightEnable( 1 , FALSE );

	// Setting Spot Light
	m_SpotLight.Type				= D3DLIGHT_SPOT;
	m_SpotLight.Diffuse.r			= m_SpotLight.Ambient.r = m_SpotLight.Specular.r = 0.0f;
	m_SpotLight.Diffuse.g			= m_SpotLight.Ambient.g = m_SpotLight.Specular.g = 0.0f;
	m_SpotLight.Diffuse.b			= m_SpotLight.Ambient.b = m_SpotLight.Specular.b = 1.0f;
	m_SpotLight.Diffuse.a			= m_SpotLight.Ambient.a = m_SpotLight.Specular.a = 1.0f;
	m_SpotLight.Range				= 200.0f;
	m_SpotLight.Position			= D3DXVECTOR3( 10.0f ,  10.0f  , -10.0f );
	m_SpotLight.Direction			= D3DXVECTOR3( 10.0f , -1.0f , -10.0f );
	m_SpotLight.Attenuation0		= 0.0f;
	m_SpotLight.Attenuation1		= 0.001f;
	m_SpotLight.Attenuation2		= 0.0f;
	m_SpotLight.Theta				= 0.2f;
	m_SpotLight.Phi					= 0.4f;
	m_SpotLight.Falloff				= 1.0f;

	g_pd3dDevice->SetLight( 2 , &m_SpotLight );
	g_pd3dDevice->LightEnable( 2 , FALSE );
    
	// Lighting! + Ambient!!
	g_pd3dDevice->SetRenderState( D3DRS_LIGHTING , TRUE );
	g_pd3dDevice->SetRenderState( D3DRS_AMBIENT , 0x50505050 );	
    
    return TRUE;
}

bool CLight::Frame()
{
    return TRUE;
}

bool CLight::Render()
{
    return TRUE;
}

bool CLight::Release()
{
    return TRUE;
}
